// pages/home/homeLeiBo/personalHousing/personalHousing.js
import Https from "../../../../utils/api.js"
const http = new Https
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		imgs:"../../../../assets/home/butie.png",
		msg:"位置:此房,前面是小区的绿化带,景观绝好,下楼2m出小区,上班方便。+户型:1室1卫0阳台45m²,保养的太好了,看房方便。装修:普通服务:资深经纪人24h服务热线*承诺:所有离源均为真实有效房源,恭候您的来电咨询！",
		collect :false,
		info:{
			name:"周某人",
			type:"0",
			phone:"",
		},
		//楼盘经纬度
		longitude: 104.07,
		latitude: 30.67,
		building:{},
		markers: [{
			id: 0,
			latitude: 30.67,
			longitude: 104.07,
			iconPath: "/assets/biaojidianwei.png",
			width: 30,
			height: 30,
			label: {
				content: '君豪新城', //文本
				color: '#FF0202', //文本颜色
				borderRadius: 3, //边框圆角
				borderWidth: 1, //边框宽度
				borderColor: '#FF0202', //边框颜色
				bgColor: '#ffffff', //背景色
				padding: 5, //文本边缘留白
				textAlign: 'center' //文本对齐方式。有效值: left, right, center
			}
		}],
		// 轮播图
		images:[
			"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4018216757,316269704&fm=26&gp=0.jpg",
			"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4018216757,316269704&fm=26&gp=0.jpg",
			"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4018216757,316269704&fm=26&gp=0.jpg",
			"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4018216757,316269704&fm=26&gp=0.jpg",
		],
		// 活动图
		advertisingImage: [],
		advertisingImage1: [],
		houseInfo: [],
		config: [],
		// 个人房源
		personalHousing: [],
		// 优质房源
		excellentHouse: [],
		// 周边新房
		nearbyNewHouse: [{
			id: '1',
			zd: '1',
			img: '/assets/home/homeListItem/home01.png',
			title: '合力达卓越南城',
			stmel: '北海区',
			stmels: '东路101号',
			number: '15000',
			specifications: '2室1厅',
			squaremeter: '67.7',
			homesuper: '精装修',
			q1: "海景",
			q2: "别墅",
			homeN: 1,
			homeS: "停售"
		},
		{
			id: '2',
			img: '/assets/home/homeListItem/home01.png',
			title: '中心海城',
			stmel: '途家丛',
			stmels: '赤岭路110路',
			number: '11000',
			q1: "海景",
			q2: "别墅",
			homeN: 2,
			homeS: "在售"
		},
		{
			id: '3',
			img: '/assets/home/homeListItem/home01.png',
			title: '广夏大楼',
			stmel: '梅溪湖',
			stmels: '鼎奥国际',
			number: '14000',
			q1: "海景",
			q2: "别墅",
			homeN: 2,
			homeS: "在售"
		},
		{
			id: '4',
			img: '/assets/home/homeListItem/home01.png',
			title: '溪岛精装套三，靠地铁',
			stmel: '长沙县',
			stmels: '小遂溪岛',
			number: '90000',
			q1: "海景",
			q2: "别墅",
			homeN: 2,
			homeS: "在售"
		}
		]
	},
	/**
	 * 生命周期函数--监听页面加载
	 */

	onLoad(options) {
		console.log(options)
		http.request("browse",{fang_id:options.id,fang_type:0},"POST").then((res)=>{
			console.log(res)

		})
		this.iscollect(options.id);
		// 传递参数动态修改标题
		this.setData({fangid:options.id})
	 http.request('secondHouse/id',{
		 id:options.id
	 }).then(res=>{
		 console.log(res)
		 wx.setNavigationBarTitle({
			title: res.data.house_estate
		})
		 this.setData({
			 building:res.data
		 })
	 })

		http.request('secondHouse/id', {
			id: options.id
		}).then(res => {
			console.log(res)
			wx.setNavigationBarTitle({
				title: res.data.house_estate
			})
			var markers = []
			markers.push({
				id: res.data.id,
				latitude: res.data.latitude,
				longitude: res.data.longitude,
				iconPath: "../../../../assets/biaojidianwei.png",
				width: 30,
				height: 30,
				label: {
					content: res.data.house_estate, //文本
					color: '#FF0202', //文本颜色
					borderRadius: 3, //边框圆角
					borderWidth: 1, //边框宽度
					borderColor: '#FF0202', //边框颜色
					bgColor: '#ffffff', //背景色
					padding: 5, //文本边缘留白
					textAlign: 'center' //文本对齐方式。有效值: left, right, center
				}
			})
			var info = []
			info.push({
				name: "单价",
				price: res.data.price + "元"
			},
				{
					name: "面积",
					price: res.data.area
				},
				{
					name: "户型",
					price: res.data.house_type.name
				},
				{
					name: "朝向",
					price: res.data.forward.name
				},
				{
					name: "楼层",
					price: res.data.floor
				},
				{
					name: "装修",
					price: res.data.fit_up.name
				},
				{
					name: "小区",
					price: res.data.house_estate
				})
			this.setData({
				building: res.data,
				houseInfo: info,
				msg: res.data.desc,
				markers: markers
			})
		})
	},
	goodHouse() {
		let pages = getCurrentPages();
		let currPage = pages[pages.length - 1];
		let prevPage = pages[pages.length - 2];
		prevPage.setData({
			currentInexs: 1,
		});
		wx.navigateBack({
			delta: 1
		})
	},
	personal() {
		wx.navigateBack({
			delta: 1
		})
	},
	newHouse() {
		wx.navigateTo({
			url: "/pages/home/newHouseList/newHouseList"
		})
	},
	collect(){
		if(this.data.collect){
			http.request("cancel",{fang_id:this.data.fangid},"POST").then((res)=>{
				console.log(res)
				if(res.code == 200){
					wx.showToast({
						title:res.message,
						icon:"none"
					})
					this.setData({
						collect:false
					});
				}else{
						wx.showToast({
							title:res.message,
							icon:"none"
						})
				}
			})
		}else{
			http.request("collect",{fang_id:this.data.fangid,fang_type:0},"POST").then((res)=>{
				console.log(res)
				if(res.code == 200){
					wx.showToast({
						title:"收藏成功",
						icon:"none"
					})
					this.setData({
						collect:true
					});
				}else{
						wx.showToast({
							title:"收藏失败",
							icon:"none"
						})
				}
			})
		}
	},
	previewImage() {
		let that = this;
		wx.previewImage({
			urls: that.data.images
		})
	},
	other() {
		wx.navigateTo({
			url: 'other/other'
		})
	},
	complain() {
		wx.navigateTo({
			url: 'complain/complain'
		})
	},

	deal(e) {
		wx.navigateTo({
      url: '/pages/chatAgent/chatAgent?id=' + e.currentTarget.dataset.id + '&name=' + e.currentTarget.dataset.name,
    })
	},

	iscollect(fangid){
		console.log(fangid)
		http.request("isCollect",{fang_id:fangid},"POST").then((res)=>{
			console.log(res)
			if(res.code == 200){
				this.setData({collect:res.data})
			}else{
				this.setData({collect:res.data})
			}
		})
	},

	freeTell: function(){
    var agent = this.data.building.agent
    wx.makePhoneCall({
      phoneNumber: agent.phone,
    })
  },

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})
